package com.luhui.codereview.api

import com.luhui.codereview.URL_PREFIX
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import okhttp3.OkHttpClient


/**
 * @author  luhui
 * @date  2019/10/27 21:37
 * @version 1.0
 */
object ApiManager{
    private val codeReviewApi :CodeReviewApi

    init {
        val retrofit = Retrofit.Builder()
                .baseUrl(URL_PREFIX)
                .addConverterFactory(GsonConverterFactory.create())
                .client(genericClient())
                .build()
        this.codeReviewApi = retrofit.create(CodeReviewApi::class.java)
    }

    /**
     * 获取api实例
     */
    fun getApiInstance():CodeReviewApi{
        return codeReviewApi
    }

    fun genericClient(): OkHttpClient {
         return OkHttpClient.Builder()
                //仅测试环境使用，方便地址被fiddler抓取，方便调问题
//                .proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress("localhost", 8888)))
                .build()

    }


}